package chapter8.Encapsulation;

public class Account {
    private String name;
    private double salary;
    private String passwd;

    public Account() {
    }

    public Account(String name, double salary, String passwd) {
        setName(name);
        setSalary(salary);
        setPasswd(passwd);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        if (name.length()>=2&&name.length()<=4){
        this.name = name;}
        else{
            System.out.println("名字长度不合适");
        }
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        if (salary>20){
        this.salary = salary;}
        else{
            this.salary = 20;
            System.out.println("余额不合适");
        }
    }

    public String getPasswd() {
        return passwd;
    }

    public void setPasswd(String passwd) {
        if (passwd.length()==6){
        this.passwd = passwd;}
        else{
            System.out.println("密码长度不合适");
           this.passwd = "123456";
        }
    }
    public String info(){
        return "name="+name+"sal="+salary+"passwd="+passwd;
    }
}
